package cn.structure.edp;

import cn.structure.BaseEntity;
import cn.structure.ClassEntity;
import cn.structure.VariableEntity;

import java.util.Objects;

public class Retrieve extends EdpEntity {
    private ClassEntity sourceAccess;   // 主类持有另一个类的引用字段
    private ClassEntity sinkHolder; // 主类
    private ClassEntity retrieved;  // 第三个类
    private VariableEntity sink;    // 主类持有第三个类类型的变量
    private BaseEntity source;  // 另一个类的字段/方法，主类调用它更新sink

    public Retrieve(ClassEntity sourceAccess, ClassEntity sinkHolder, ClassEntity retrieved, VariableEntity sink, BaseEntity source) {
        super();
        this.sourceAccess = sourceAccess;
        this.sinkHolder = sinkHolder;
        this.retrieved = retrieved;
        this.sink = sink;
        this.source = source;
    }

    public enum role {
        sourceAccess, sinkHolder, retrieved, sink, source
    }

    public ClassEntity getSourceAccess() {
        return sourceAccess;
    }

    public void setSourceAccess(ClassEntity sourceAccess) {
        this.sourceAccess = sourceAccess;
    }

    public ClassEntity getSinkHolder() {
        return sinkHolder;
    }

    public void setSinkHolder(ClassEntity sinkHolder) {
        this.sinkHolder = sinkHolder;
    }

    public ClassEntity getRetrieved() {
        return retrieved;
    }

    public void setRetrieved(ClassEntity retrieved) {
        this.retrieved = retrieved;
    }

    public VariableEntity getSink() {
        return sink;
    }

    public void setSink(VariableEntity sink) {
        this.sink = sink;
    }

    public BaseEntity getSource() {
        return source;
    }

    public void setSource(BaseEntity source) {
        this.source = source;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Retrieve{\n\t");
        sb.append(super.toString());
        sb.append("\n\t\"sourceAccess\":")
                .append(sourceAccess);
        sb.append(",\n\t\"sinkHolder\":")
                .append(sinkHolder);
        sb.append(",\n\t\"retrieved\":")
                .append(retrieved);
        sb.append(",\n\t\"sink\":")
                .append(sink);
        sb.append(",\n\t\"source\":")
                .append(source);
        sb.append("\n}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        Retrieve retrieve = (Retrieve) o;
        return Objects.equals(sourceAccess, retrieve.sourceAccess) &&
                Objects.equals(sinkHolder, retrieve.sinkHolder) &&
                Objects.equals(retrieved, retrieve.retrieved) &&
                Objects.equals(sink, retrieve.sink) &&
                Objects.equals(source, retrieve.source);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), sourceAccess, sinkHolder, retrieved, sink, source);
    }
}
